#ifndef BOXGROUP_H
#define BOXGROUP_H

#include <OneBox.h>
#include <QGraphicsItemGroup>
#include <QList>
#include <QObject>
#include <QPointF>
#include <QPropertyAnimation>
#include <QRandomGenerator>
#include <QTimer>
class BoxGroup : public QObject, public QGraphicsItemGroup
{
    Q_OBJECT

public:
    enum BoxShape{
        IShape,
        JShape,
        LShape,
        OShape,
        SShape,
        TShape,
        ZShape,
        RandomShape
    };
    explicit BoxGroup(QGraphicsItem *parent = nullptr, BoxShape shape = RandomShape);
    QRectF boundingRect() const;
    void keyPressEvent(QKeyEvent *event);
    bool isColliding();
    void setGameFlag(bool gameFlag);
    QPainterPath shape() const;
    void startTimer(int msec);
    void endTimer();
    void moveToScreen();
    void clearBox();
signals:
    void needNewBox();
private:
    BoxShape currentShape;
    QList<OneBox*> *members;
    int boxPosGroup[7][4][2] = {{-30, -10, -10, -10, 10, -10, 30, -10},
                                {-10, 30, 10, 30, 10, 10, 10, -10},
                                {-10, 30, -10, 10, -10, -10, 10, 30},
                                {-10, -10, -10, 10, 10, -10, 10, 10},
                                {-10, 10, 10, 10, 10, -10, 30, -10},
                                {-10, -10, 10, -10, 10, 10, 30, -10},
                                {-10, -10, 10, -10, 10, 10, 30, 10}};
    QRandomGenerator *randomGenerator;
    bool gameFlag;
    QTimer *timer;
    void initBoxGroup(BoxShape);
    void moveOneStep();
    void moveBoxToScene();
};

#endif // BOXGROUP_H
